package com.factory;

import com.entity.UsbDevice;
import com.entity.UsbDeviceType;

import java.lang.reflect.Constructor;

public class UsbDeviceFactory {

    public static UsbDevice makeUsbDevice(UsbDeviceType type, String brand, int size) throws Exception {
        Class clazz ; //类对象。
        Constructor constructor;
        UsbDevice obj = null;
        switch (type) {
            case UDISK:

                clazz = Class.forName("com.entity.UDisk");
                constructor = clazz.getDeclaredConstructor(String.class,int.class);
                constructor.setAccessible(true);
                obj = (UsbDevice) constructor.newInstance(new Object[]{brand,size});
                break;

            case MOVEDISK:
                clazz = Class.forName("com.entity.MovedDisk");
                constructor = clazz.getDeclaredConstructor(String.class,int.class);
                constructor.setAccessible(true);
                obj = (UsbDevice) constructor.newInstance(new Object[]{brand,size});
                break;
            case MOBILE:
                System.out.println("准备生产手机...");
                break;
            case PRINTER:
                System.out.println("准备生产打印机...");
                break;
        }
        return obj;
    }
}
